package com.jintian.smart.platform.system.controller;

import com.jintian.smart.base.api.support.form.TableColumnUpdateForm;
import com.jintian.smart.kernel.core.constant.SwaggerTagConst;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.platform.system.service.TableColumnService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import com.jintian.smart.kernel.common.controller.SupportBaseController;
import com.jintian.smart.kernel.common.context.ContextHolder;
import com.jintian.smart.kernel.core.annotation.RepeatSubmit;
import org.springframework.web.bind.annotation.*;

/**
 * 表格自定义列（前端用户自定义表格列，并保存到数据库里）
 */
@RestController
@Tag(name = SwaggerTagConst.Support.TABLE_COLUMN)
@RequestMapping("/sys/tableColumn")
public class TableColumnController extends SupportBaseController {
    @Resource
    private TableColumnService tableColumnService;

    @Operation(summary = "修改表格列")
    @PostMapping("/update")
    @RepeatSubmit
    public ResponseDTO<String> updateTableColumn(@RequestBody @Valid TableColumnUpdateForm updateForm) {
        return tableColumnService.updateTableColumns(ContextHolder.getUser(), updateForm);
    }

    @Operation(summary = "恢复默认（删除）")
    @GetMapping("/delete/{tableId}")
    @RepeatSubmit
    public ResponseDTO<String> deleteTableColumn(@PathVariable Integer tableId) {
        return tableColumnService.deleteTableColumn(ContextHolder.getUser(), tableId);
    }

    @Operation(summary = "查询表格列")
    @GetMapping("/getColumns/{tableId}")
    public ResponseDTO<String> getColumns(@PathVariable Integer tableId) {
        return ResponseDTO.ok(tableColumnService.getTableColumns(ContextHolder.getUser(), tableId));
    }
}
